$(function(){
	queryUrlsData(1);
	//添加角色
	$("#importOrder").click(function(){
		window.top.location.href =WEB_ROOT+"/order_info/order_import_init";
	});
	$("#exportOrder").click(function(){
		var batchId = $.trim($("#batchId").val());
		var expressNo = $.trim($("#expressNo").val());
		var identityCard = $.trim($("#identityCard").val());
		var mainOrdId = $.trim($("#mainOrdId").val());
		var state = $("#state").val();
		var url = WEB_ROOT+"/order_info/order_export";
		var form = $("<form>");
		form.attr('style','display:none');
		form.attr('target','');
		form.attr('method','post');
		form.attr('action',url);
		$("<input type='text' name='batchId' value='"+batchId+"' />").appendTo(form);
		$("<input type='text' name='expressNo' value='"+expressNo+"' />").appendTo(form);
		$("<input type='text' name='identityCard' value='"+identityCard+"' />").appendTo(form);
		$("<input type='text' name='state' value='"+state+"' />").appendTo(form);
		$("<input type='text' name='mainOrdId' value='"+mainOrdId+"' />").appendTo(form);
		$('body').append(form);
		form.submit();
		form.remove();
	});
	$("#exportPay").click(function(){
		var batchId = $.trim($("#batchId").val());
		var expressNo = $.trim($("#expressNo").val());
		var identityCard = $.trim($("#identityCard").val());
		var state = $("#state").val();
		var mainOrdId = $.trim($("#mainOrdId").val());
		var url = WEB_ROOT+"/order_info/pay_export";
		var form = $("<form>");
		form.attr('style','display:none');
		form.attr('target','');
		form.attr('method','post');
		form.attr('action',url);
		$("<input type='text' name='batchId' value='"+batchId+"' />").appendTo(form);
		$("<input type='text' name='expressNo' value='"+expressNo+"' />").appendTo(form);
		$("<input type='text' name='identityCard' value='"+identityCard+"' />").appendTo(form);
		$("<input type='text' name='state' value='"+state+"' />").appendTo(form);
		$("<input type='text' name='mainOrdId' value='"+mainOrdId+"' />").appendTo(form);
		$('body').append(form);
		form.submit();
		form.remove();
	});
	$("#downloadTemplate").click(function(){
		var url = WEB_ROOT+"/main/downloadExcel";
		var form = $("<form>");
		form.attr('style','display:none');
		form.attr('target','');
		form.attr('method','post');
		form.attr('action',url);
		$("<input type='text' name='fileName' value='订单导入模版.xlsx' />").appendTo(form);
		$('body').append(form);
		form.submit();
		form.remove();
	});
	$("#pay").click(function(){
		var idLst = [];
		$('input[name=ordInfoId]:checkbox:checked').each(function(){
			idLst.push($(this).val());
		});
		if (idLst.length == 0) {
			eDialog.alert('请选择需要支付订单');
			return;
		}
		$.ajax({
			url: GLOBAL.WEBROOT+"/order_info/pay",
	        data:[{name:'idLst',value:idLst}],
	        type:"post",
	        dataType:"json",
	        async:true,
		    cache:true,
	        success: function (data){
	        	queryUrlsData(1);
	        },
	        error:function(XMLHttpRequest, textStatus, errorThrown){
	        	
	        }
		});
	});
});
function queryUrlsData(pageNo){
    var params = {
    	batchId:$.trim($("#batchId").val()),
    	expressNo:$.trim($("#expressNo").val()),
    	identityCard:$.trim($("#identityCard").val()),
    	state:$("#state").val(),
    	mainOrdId:$('#mainOrdId').val(),
        pageNo:pageNo,
        pageSize:50
    };

    ajaxLoadPage(params,WEB_ROOT+"/order_info/order_list",$("#orderlist-div-id"),function(){
        $("#urlPagerId").pager({callback:function(pageNo){
            queryUrlsData(pageNo);
        }});
    	$('#checkAll').on('click', function(){
    		if($(this).is(':checked')) {
        		$('input[name=ordInfoId]').prop('checked', 'true');
    		} else {
        		$('input[name=ordInfoId]').removeAttr('checked');
    		}
    	});
    });
}